#pragma once

#include "MMSystem.h"
#include "SAPIEventCallback.h"
#include "StreamReceiver.h"

/*
Class that fully initializes one voice (default or optionally a named one).
User of this class must call CoInitialize before calling Initialize, and must call CoUninitialize after Destroy
*/
class SAPIController
{
public:
	SAPIController(void);
	~SAPIController(void);

	HRESULT Initialize(SAPIEventCallback* eventCallback, StreamReceiver* streamReceiver, unsigned int samplingRate, WCHAR* voiceName);
	
	/*
	Sets the currently speaking voice (see VoiceNames.h)
	*/
	HRESULT SetVoiceName(WCHAR* voiceName);

	void Destroy();
	
	/*
	Returns the voice controlled by this SAPIController.
	NULL if called before Initialize, or if initialization failed.
	*/
	ISpVoice* GetVoice();

	/*
	Adds the message to the list of text that the voice should speak. If purgeBeforeSpeak=true, then message is what will be produced next by the voice.
	*/
	HRESULT Speak(WCHAR* message, bool purgeBeforeSpeak);

	


private:
	SAPIEventCallback* eventCallback;
	SAPIEventCallbackImpl eventCallbackImpl;

	StreamReceiver* streamReceiver;
	StreamReceiverImpl streamReceiverImpl;

	ISpVoice* pVoice;
	WAVEFORMATEX cachedWaveFormat;
};
